//
//  TKIMImageFooterView.m
//  TKPhotoSelectDemo
//
//  Created by liupm on 16/4/21.
//  Copyright © 2016年 liupm. All rights reserved.
//

#import "TKIMImageFooterView.h"
#import "TKIMImagePickerDefinition.h"

@implementation TKIMImageFooterView

-(void)drawRect:(CGRect)rect
{
    [self addSubview:self.previewButton];
    [self addSubview:self.confirmButton];
    [self addSubview:self.photoCount];
}

/**
 *  @Author lpm, 16-04-21 11:04:40
 *
 *  @brief  设置计数
 */
-(void)setCount:(NSInteger)count
{
    self.photoCount.hidden = !count;
    self.photoCount.text = [NSString stringWithFormat:@"%d", count];
    if (self.photoCount.hidden)
    {
        self.previewButton.enabled = NO;
        self.confirmButton.enabled = NO;
    }
    else
    {
        self.previewButton.enabled = YES;
        self.confirmButton.enabled = YES;
    }
}


/**
 *  @Author lpm, 16-04-21 13:04:45
 *
 *  @brief  确定
 */
-(void)confirm
{
    [self routerEventWithName:TKIMImageConfirmEvent userInfo:nil];
}


/**
 *  @Author lpm, 16-04-21 13:04:01
 *
 *  @brief  预览
 */
-(void)preview
{
    [self routerEventWithName:TKIMImagePreviewEvent userInfo:nil];
}


#pragma mark 属性

-(UIButton *)confirmButton
{
    if (!_confirmButton)
    {
        CGFloat x = self.frame.size.width - 75;
        _confirmButton = [[UIButton alloc] initWithFrame:CGRectMake(x, 7, 60, 30)];
        _confirmButton.enabled = NO;
        _confirmButton.backgroundColor = [UIColor colorWithRed:0.23 green:0.64 blue:0.93 alpha:1];
        [_confirmButton setTitle:@"发送" forState:UIControlStateNormal];
        [_confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_confirmButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
        _confirmButton.layer.cornerRadius = 3.0f;
        _confirmButton.layer.masksToBounds = YES;
        _confirmButton.titleLabel.font = [UIFont systemFontOfSize:16.0f];
        [_confirmButton addTarget:self action:@selector(confirm) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmButton;
}


-(UILabel *)photoCount
{
    if (!_photoCount)
    {
        CGFloat x = self.confirmButton.frame.size.width +self.confirmButton.frame.origin.x-12;
        _photoCount = [[UILabel alloc] initWithFrame:CGRectMake(x, 2, 20, 20)];
        _photoCount.font = [UIFont systemFontOfSize:13.f];
        _photoCount.textColor = [UIColor whiteColor];
        _photoCount.backgroundColor = [UIColor redColor];
        _photoCount.layer.cornerRadius = 10;
        _photoCount.layer.masksToBounds = YES;
        _photoCount.hidden = YES;
        _photoCount.textAlignment = NSTextAlignmentCenter;
    }
    return _photoCount;
}

-(UIButton *)previewButton
{
    if (!_previewButton)
    {
        CGFloat x = 10;
        _previewButton = [[UIButton alloc] initWithFrame:CGRectMake(x, 2, 50, 40)];
        _previewButton.backgroundColor = [UIColor clearColor];
        _previewButton.enabled = NO;
        [_previewButton setTitle:@"预览" forState:UIControlStateNormal];
        [_previewButton setTitleColor:[UIColor colorWithRed:0.23 green:0.64 blue:0.93 alpha:1] forState:UIControlStateNormal];
        [_previewButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
        _previewButton.titleLabel.font = [UIFont systemFontOfSize:16.0f];
        [_previewButton addTarget:self action:@selector(preview) forControlEvents:UIControlEventTouchUpInside];
    }
    return _previewButton;
}

@end
